import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import {
  ArrayNotEmpty,
  IsArray,
  IsDateString,
  IsNumber,
  IsOptional,
  IsString,
  Min,
  ValidateNested,
} from "class-validator";

export class ItemDto {
  @IsString()
  @ApiProperty({
    description: "订单ID",
  })
  orderId: string;

  @IsNumber()
  @ApiProperty({
    description: "该订单送货数量",
  })
  @Min(1)
  quantity: number;
}

export class CreateDeliveryDto {
  @IsString()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "送货地址",
  })
  address?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "联系方式",
  })
  contact?: string;

  @IsString()
  @ApiProperty({
    description: "客户ID",
  })
  clientId: string;

  @IsDateString()
  @ApiProperty({
    description: "送货时间",
  })
  deliveryDate: string;

  @ValidateNested({ each: true })
  @IsArray()
  @ArrayNotEmpty()
  @Type(() => ItemDto)
  @ApiProperty({
    type: [ItemDto],
    description: "送货项目",
  })
  items: ItemDto[];
}
